from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains


driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://www.baidu.com")
time.sleep(2)

# 鼠标悬停至【设置】
ActionChains(driver).move_to_element(driver.find_element(By.ID, "s-usersetting-top")).perform()
time.sleep(2)

# 点击-搜索设置
driver.find_element(By.XPATH, "//a[@class='setpref first']").click()
time.sleep(2)

# 点击-保存设置
driver.find_element(By.CSS_SELECTOR, "a[class^=prefpanelgo]").click()
time.sleep(2)

# 获取弹出框文本值
print("弹出框内文本为：", driver.switch_to.alert.text)

# 确认警告
driver.switch_to.alert.accept()

time.sleep(10)
driver.quit()